package com.cloudfun.campusshare.sender;

import com.cloudfun.campusshare.common.constant.DelayConsumeAction;
import com.cloudfun.campusshare.common.constant.DelayMsgType;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.function.Consumer;

/**
 * @author : zhangyongjie
 * @version : 1.0
 * @createTime : 2020/6/18 17:26
 * @description : 延时消息属性
 */
@Data
@Builder
public class DelayMessage implements Serializable {

    private static final long serialVersionUID = -1327182637818786784L;

    private String orderId;

    private String deviceId;

    private String userId;

    private Long timeStamp;

    private DelayMsgType type;

//    private Consumer<String> consumer;

    private DelayConsumeAction consumerType;
    public DelayMessage() {
    }

    public DelayMessage(String orderId, String deviceId, String userId, Long timeStamp, DelayMsgType type, DelayConsumeAction consumerType) {
        this.orderId = orderId;
        this.deviceId = deviceId;
        this.userId = userId;
        this.timeStamp = timeStamp;
        this.type = type;
        this.consumerType = consumerType;
    }

    public DelayMessage(String orderId, String deviceId, String timeStamp, String type, String consumerType) {
        this.orderId = orderId;
        this.deviceId = deviceId;
        this.timeStamp = Long.valueOf(timeStamp);
        this.type = DelayMsgType.valueOf(type);
        this.consumerType = DelayConsumeAction.valueOf(consumerType);
    }

    public static class Builder {
        DelayMessage instance;

        public Builder() {
            this.instance = new DelayMessage();
        }

        public Builder orderId(String orderId) {
            this.instance.orderId = orderId;
            return this;
        }

        public Builder deviceId(String deviceId) {
            this.instance.deviceId = deviceId;
            return this;
        }

        public Builder userId(String userId) {
            this.instance.userId = userId;
            return this;
        }

        public Builder type(DelayMsgType type) {
            this.instance.type = type;
            return this;
        }

        public Builder consumerType(DelayConsumeAction consumerType) {
            this.instance.consumerType = consumerType;
            return this;
        }

        public DelayMessage build() {
            this.instance.timeStamp = System.currentTimeMillis();
            return this.instance;
        }
    }
}
